﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web;
using System.Web.Mvc;

namespace MyHelper
{
    public static class MenuExtension
    {
        public static string Menu(this HtmlHelper helper, Object items)
        {
            return "<menu>" + MenuExtension.GetItems(items) + "</menu>";
        }

        public static string GetItems(Object items)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }
            if (items is IEnumerable == false)
            {
                throw new InvalidCastException("Item must be IEnumerable");
            }

            var menuItems = (IEnumerable)items;
            var builder = new StringBuilder();
            foreach (Object o in menuItems)
            {
                builder.AppendFormat("<li><a href=#>{0}</a></li>", HttpUtility.HtmlEncode(o.ToString()));
            }
            return builder.ToString();
        }

    }
}
